from flask import Flask,render_template,request,redirect,url_for
import sys
sys.path.append('.')
from celeryadmin.celery_admin import context_manager,celery_client

# 代码参考自https://github.com/baranbartu/djcelery-admin
app=Flask(__name__)

@app.route('/celery_dashboard')
def celery_dashboard():
    return render_template('celery_dashboard.html',dashboard=context_manager.dashboard)

@app.route('/celery_operation')
def celery_operation():
    command=request.args.get('command')
    parameter=request.args.get('parameter')
    celery_client.execute(command,parameter)
    return redirect(url_for('.celery_dashboard'))

@app.route('/celery_tasks')
def celery_tasks():
    return render_template('celery_tasks.html',tasks=context_manager.tasks)

if __name__=='__main__':
    app.run(host='0.0.0.0',port=5001,debug=True)